/** @Date 下午2:53:48
  * @version 1.0.0
  * @author shangyd
  * Copyright (c) 2015
  */
package com.sdw.soft.test.mybatis;

import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MyBatisDemo {

	public static void main(String[] args) {
		SqlSession session = null;
		try {
			String config = "com/sdw/soft/test/mybatis/mybatis.xml";
			InputStream inputStream = Resources.getResourceAsStream(config);
			SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
			session = sqlSessionFactory.openSession();
			User user = new User("476c2bec-3ee6-43a1-942a-0e20359e5f40","sdw2330976","root",25,"xinyang",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
			session.insert("addUser",user);
			session.commit();
			session.close();
		} catch (IOException e) {
			e.printStackTrace();
			session.rollback();
			session.close();
		}
		
	}
}
